<template>
  <a-card :bordered="false">
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="crudCreate" type="primary" icon="plus">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table 
        ref="table" 
        size="middle" 
        rowKey="id" 
        bordered
        :scroll="{ x: 1300 }"
        :columns="columns" 
        :dataSource="tableData" 
        :loading="loading" 
        @change="handleTableChange"
      >
        <!--操作-->
        <span slot="action" slot-scope="text, record" >
          <a-button type="primary" @click="crudUpdate(record)" icon="edit"></a-button>
          <a-popconfirm title="确定删除吗?" @confirm="() => crudDelete(record.id)" okText="删除" cancelText="取消">
            <a-button type="danger" icon="delete" />
          </a-popconfirm>
        </span>
        <!--图片预览块-->
        <span slot="imgPath" slot-scope="text, record">
          <img :src="record.img" width="100px" height="100px" />
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <city-modal ref="updateForm" @closeModal="closeModal"></city-modal>
  </a-card>
</template>

<script>
import cityModal from './modules/cityModal'
import ApiTree from "@/api/common/city";
import { Slime, crud } from "@/mixins/slime";

export default {
  name: "city",
  mixins: [Slime],
  components: {
    cityModal
  },
  data() {
    return {
      tableData: [],
      columns: [
        {
          title: "城市名称",
          align: "center",
          dataIndex: "name",
        },
        {
          title: "首字母",
          align: "center",
          dataIndex: "first",
        },
        {
          title: "状态",
          align: "center",
          dataIndex: "status",
          customRender: function(status) {
            if(status == 0){
              return '关闭'
            }else{
              return '开启'
            }
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
    };
  },
  created() {
    crud(ApiTree);
    this.loadData();
  },
  methods: {
    // 加载表格数据
    loadData(arg) {
      this.loadDataPack(arg).then((res) => {
        let tableData = [];
        if (res.result) {
          tableData = res.result;
        }
        this.tableData = tableData;
      });
    },
    //详情
    handleDetail(record){
      this.$router.push({ path: '/orderDetail?id='+record.id})
    },
    closeModal(){
      this.loadData();
    }
  },
};
</script>
<style scoped>
</style>